package com.yami.shop.common.util;



import com.yami.shop.common.model.ShopConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * */
public class ShopSysConfig {


    private static final Logger logger = LoggerFactory.getLogger(ShopSysConfig.class);


    public static Map<String,String> shopConfigCacheMap = new ConcurrentHashMap<>();


    public static void put(List<ShopConfig> sysConfigList){
        for(ShopConfig sysConfig:sysConfigList){
            shopConfigCacheMap.put(sysConfig.getParamKey(),sysConfig.getParamValue());
        }

    }

    /**
     * 获取配置值
     * */
    public static String getValue(String  key){
        try{
            return shopConfigCacheMap.get(key);
        }catch (Exception e){
            logger.error("systemCacheMap error: key is null:{}",key);
            e.printStackTrace();
        }
        return "";
    }

    /**
     * 获取配置值to int
     * */
    public static Integer getValueToInt(String  key){
        try{
            return Integer.valueOf(shopConfigCacheMap.get(key));
        }catch (Exception e){
            logger.error("systemCacheMap error: key is null:{}",key);
            e.printStackTrace();
        }
        return 0;
    }


}
